package com.xiaozhi.dao;

import java.util.List;

import com.xiaozhi.entity.SysUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户资料 数据层
 * 
 * @author Joey
 * 
 */
public interface UserMapper {
    SysUser selectUserByUserId(@Param("userId") Integer userId);
    @Select("select * from sys_user where openId = #{openId}")
    SysUser selectUserByOpenId(@Param("openId") String openId);

    SysUser selectUserByUsername(@Param("username") String username);

    SysUser selectUserByEmail(@Param("email") String email);

    SysUser query(@Param("username") String username, @Param("startTime") String startTime,
            @Param("endTime") String endTime);

    int add(SysUser user);

    @Update({"update sys_user set username=#{username},nickName=#{nickName},avatar=#{avatar},avatarUrl=#{avatarUrl},",
    "name=#{name},state=#{state},tel=#{tel},email=#{email} where openId=#{openId}"})
    int update(SysUser user);
    
    @Update("update sys_user set token=#{token} where openId=#{openId}")
    int updateToken(SysUser user);

    List<SysUser> queryUsers(@Param("user") SysUser user, @Param("startTime") String startTime,
            @Param("endTime") String endTime);

    int generateCode(SysUser user);

    int queryCaptcha(@Param("code") String code, @Param("email") String email);
    
    @Select("select * from sys_user where openId = #{openId}")
    SysUser getOne(String openId);
}
